//
//  ByViewMyOrderListTable.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/25.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewMyOrderListTable.h"

// cell
#import "ByCellMyOrderForProduct.h"

// view
#import "ByViewMyOrderSectionHeader.h"

@interface ByViewMyOrderListTable() <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *table;
@end

@implementation ByViewMyOrderListTable
{
    NSInteger _items;
}


- (void)setFrame:(CGRect)frame {
    
    [super setFrame:frame];

    self.table = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.table.backgroundColor = BY_BG_COLOR;
    self.table.delegate = self;
    self.table.dataSource = self;
    [self addSubview:self.table];
    
    [self.table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self.table registerClass:[ByCellMyOrderForProduct class] forCellReuseIdentifier:@"productCell"];
}
- (void)setIndex:(NSInteger)index {
    
    _index = index;
    
    __weak typeof(self) wself = self;
    if (_index == 0) {
        self.contentViewDidAppear = ^(NSInteger index) {
            
            _items = arc4random_uniform(5) + 1;
            [wself.table reloadData];
        };
    }
    else {
        self.contentViewDidAppear = ^(NSInteger index) {
            
            _items = arc4random_uniform(5) + 6;
            [wself.table reloadData];
        };
    }
    
}

#pragma mark - UITableViewDataSource UITableViewDelegate
// 设置组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _items;
}
// 设置行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
// 设置单元格属性
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ByCellMyOrderForProduct *cell = [tableView dequeueReusableCellWithIdentifier:@"productCell"];
    if (cell == nil) {
        cell = [[ByCellMyOrderForProduct alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"productCell"];
    }
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [tableView fd_heightForCellWithIdentifier:@"productCell" cacheByIndexPath:indexPath configuration:^(id cell) {
        //
    }];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 50;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    ByViewMyOrderSectionHeader *header = [ByViewMyOrderSectionHeader new];
    
    return header;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return UIView.new;
}

@end
